package com.sinosoft.service.impl.system;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sinosoft.entity.DefCompany;
import com.sinosoft.mapper.DefCompanyMapper;
import com.sinosoft.service.system.ICompanyService;

@Service
public class CompanyServiceImpl implements ICompanyService {

	@Autowired
	private DefCompanyMapper companyMapper;
	
	@Override
	public List<DefCompany> selectComByCondition(DefCompany company) {
		return companyMapper.selectByCondition(company);
	}

	@Override
	public DefCompany selectComById(Long comId) {
		return companyMapper.selectById(comId);
	}

	@Override
	public Map<String, Object> initUserModifyComSelect(Long comId) {
		DefCompany company = this.selectComById(comId);
		DefCompany com = new DefCompany();
		List<DefCompany> comList = null;
		Map<String, Object> comMap = null;
		//如果当前入参机构的级别是01（最高等级，没有父节点），则直接根据Grade（等级）字段去查询同级机构
		if ("01".equals(company.getGrade())) {
			com.setGrade("01");
			comList = this.selectComByCondition(com);
		} else { //如果当前入参机构的级别不是01，则根据父机构ID去查询同级机构
			com.setParentComId(company.getParentComId());
			comList = this.selectComByCondition(com);
			comMap = initUserModifyComSelect(comList.get(0).getParentComId());
		}
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("grade", company.getGrade());
		map.put("comMap", comMap);
		map.put("comList", comList);
		return map;
	}

	
}
